package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfResourceBlacklist;
import com.yuandian.api.management.validate.InsertFlag;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.enums.BlackListType;
import com.yuandian.management.service.ConfResourceBlacklistService;
import com.yuandian.management.service.ConfResourceFilterRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 说明：通用接口配置Controller
 * @Author zfsn
 * @Date 2023/2/21 9:38
 */
@RestController
@RequestMapping("/resourceFilterRule")
@Api(tags = "业务服务资源管理-服务资源过滤规则")
public class ResourceFilterRuleController {

	@Autowired
	private ConfResourceBlacklistService confResourceBlacklistService;

	@Autowired
	private ConfResourceFilterRuleService confResourceFilterRuleService;

	/**
	 * 分页查询
	 * @param confResourceBlacklist 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "value", value = "过滤字符串描述", paramType = "body", required = false, dataTypeClass = String.class)
	})
	public R<Page<ConfResourceBlacklist>> listPage(@RequestBody ConfResourceBlacklist confResourceBlacklist) {
		return R.ok(confResourceBlacklistService.listPage(confResourceBlacklist));
	}


	/**
	 * 新增数据
	 * @param confResourceBlacklist 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@PostMapping("/save")
	public R<String> save(@Validated({InsertFlag.class}) @RequestBody ConfResourceBlacklist confResourceBlacklist) {
		return confResourceFilterRuleService.saveConfig(confResourceBlacklist);
	}


	/**
	 * 通过主键更新数据
	 * @param confResourceBlacklist 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新步骤配置表数据")
	@PutMapping
	public R<String> updateById(@Validated({UpdateFlag.class}) @RequestBody ConfResourceBlacklist confResourceBlacklist) {
		return confResourceFilterRuleService.updateById(confResourceBlacklist);
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除步骤配置表数据")
	@DeleteMapping("/delete/{ids}")
	public R<Boolean> removeById(@PathVariable("ids") List<Integer> ids){
		return R.ok(confResourceBlacklistService.removeByIds(ids));
	}

}
